/***************************************************************************
 *   Copyright (C) 2008 by Rysiek Krol,,,   *
 *   rysiek@Babylon2   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "displayoperations.h"

#include "picturelistwidgetitem.h"
#include "imageloader.h"
#include "viewerconstants.h"
#include "viewerevent.h"
#include "fileoperationshandler.h"
#include "utils.h"
#include "renamedialog.h"
#include "imagereader.h"
#include "Ui/searchdialog.h"
#include "finder.h"
#include "Ui/searchresultdialog.h"
#include "keywordsdialog.h"
#include "filesoperations.h"
#include "Ui/imageproperties.h"

#include <QTreeView>
#include <QList>
#include <QListWidget>
#include <QMessageBox>
#include <QAction>
#include <QMenu>
#include <QDirModel>
#include <QFileDialog>
#include <QInputDialog>

DisplayOperations::DisplayOperations(PictureManager *manager)
        : QObject()
{
    this->manager = manager;
    this->timer = new QTimer();
    this->slideList = new QList<QFileInfo>();
    this->setIsSlideShowActive(false);
    connect(this->timer, SIGNAL(timeout()), this, SLOT(slideShowTimerTimeout()));
    connect(this->manager->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
}


DisplayOperations::~DisplayOperations()
{
    delete this->timer;
    delete this->slideList;
}

/**
* Initialize Slide Show Procedure
*/
void DisplayOperations::slideShowSlot(FilesOperations::ActionSource source)
{
    this->setIsSlideShowActive(true);
    this->slideIndex=0;
    this->generateSlideShowFileList(source);
    if (this->slideList->count()>0)
    {
        QFileInfo file = this->slideList->at(0);
        this->manager->getItsLoader()->setCurrentSlide(file);
        if (this->slideList->count()>1)
        {
            this->manager->getItsLoader()->setNextSlide(this->slideList->at(1));
        }
        else
        {
            this->manager->getItsLoader()->setNextSlide(file);
        }
        this->isPictureLoaded = false;
        this->manager->switchGuiToPresentationMode(&file);

        this->manager->fullScreenSwichSlot();
        this->manager->getItsLoader()->setCurrentAction(ImageLoader::GetFirstSlide);
        this->manager->getItsLoader()->setGoToSleepFalse();
        this->manager->getItsLoader()->newActionCondition.wakeAll();
        this->timer->start(this->manager->getItsProperty()->getSlideShowJumpTime()*1000);
    }
}

/**
* Continue Slide Show Procedure
*/
void DisplayOperations::slideShowTimerTimeout()
{
    this->timer->stop();
    if (this->isSlideShowActive && this->slideList->count()>this->slideIndex)
    {
        if (this->slideList->count()>this->slideIndex+2) this->manager->getItsLoader()->setNextSlide(this->slideList->at(this->slideIndex+2));
        this->slideIndex++;
        this->manager->getItsLoader()->setCurrentAction(ImageLoader::GetNextSlide);
        this->manager->getItsLoader()->setGoToSleepFalse();
        this->manager->getItsLoader()->newActionCondition.wakeAll();
        this->timer->start(this->manager->getItsProperty()->getSlideShowJumpTime()*1000);
    }
}

/**
* Generates File list used to Slide Show procedure
*/
void DisplayOperations::generateSlideShowFileList(FilesOperations::ActionSource source)
{
    bool onlyDirs = true;
    if (source ==FilesOperations::BrowserWidget)
    {
        QList<QListWidgetItem *> selectedItemsIndex = this->manager->getListWidget()->selectedItems ();
        if (selectedItemsIndex.count()>0)
        {
            QListIterator<QListWidgetItem *> iterator(selectedItemsIndex);
            iterator.toFront();
            while (iterator.hasNext())
            {
                if ((dynamic_cast<PictureListWidgetItem*>(iterator.next()))->getFile().isFile())
                {
                    onlyDirs = false;
                    break;
                }
            }
            QFileInfo item;
            if (selectedItemsIndex.count()>1)
            {
                iterator.toFront();
                while (iterator.hasNext())
                {
                    item = ( dynamic_cast<PictureListWidgetItem*>(iterator.next()))->getFile();
                    if (item.isDir())
                    {
                        *this->slideList += this->generateSlideShowFileListFromDirectory( item.absoluteFilePath());
                    }
                    else
                    {
                        this->slideList->append(item);
                    }
                }

            }
            else if (selectedItemsIndex.count()==1 && onlyDirs)
            {
                iterator.toFront();
                item = (dynamic_cast<PictureListWidgetItem*>(selectedItemsIndex.at(0)))->getFile();
                *this->slideList += this->generateSlideShowFileListFromDirectory(item.absoluteFilePath());
            }
            else
            {

                for (int index = this->manager->getListWidget()->currentRow(); index<this->manager->getListWidget()->count(); index++)
                {
                    item = ( dynamic_cast<PictureListWidgetItem*>(this->manager->getListWidget()->item(index)))->getFile();
                    if (item.isDir())
                    {
                        *this->slideList += this->generateSlideShowFileListFromDirectory( item.absoluteFilePath());
                    }
                    else
                    {
                        this->slideList->append(item);
                    }
                }
            }
        }
    }
    else
    {
        QFileInfo item =(dynamic_cast<QDirModel*> (this->manager->treeWidget->model()))->fileInfo( this->manager->treeWidget->currentIndex() );
        *this->slideList = this->generateSlideShowFileListFromDirectory( item.absoluteFilePath());
    }
}

/**
* Generate and return sorted file list for slideshow from directory dir;
*/
QList< QFileInfo > DisplayOperations::generateSlideShowFileListFromDirectory(QDir dir)
{
    QList< QFileInfo > lista;
    ViewerConstants constanst;
    QFileInfoList fileList = dir.entryInfoList(constanst.getFilters(), QDir::Files);
    QListIterator<QFileInfo> iterator(fileList);
    QFileInfo item;
    while (iterator.hasNext())
    {
        item = iterator.next();
        lista.append(item);
    }
    Utils::sortItems(&lista,0,lista.count()-1,this->manager->itsProperty->getSortMethod());

    QFileInfoList dirList = dir.entryInfoList(constanst.getFilters(), QDir::Files);
    dirList = dir.entryInfoList(QStringList(), QDir::Dirs|QDir::NoDotAndDotDot);
    QListIterator<QFileInfo> dirIterator(dirList);
    while (dirIterator.hasNext())
    {
        item = dirIterator.next();
        lista += generateSlideShowFileListFromDirectory(QDir(item.absoluteFilePath()));
    }
    return lista;
}

/**
* Sets isSlideActiveValue and if value is false it clear slide show list
*/
void DisplayOperations::setIsSlideShowActive(bool theValue)
{
    isSlideShowActive = theValue;
    if (!this->isSlideShowActive) this->slideList->clear();
}

/**
* Returns Value witch tells if slide show mode is active
*/
bool DisplayOperations::getIsSlideShowActive() const
{
    return isSlideShowActive;
}

/**
* Sets itsLoader to return previous image from slideList
*/
void DisplayOperations::getPreviousSlide()
{
    QFileInfo previousSlide;
    if ((this->slideIndex >0))
    {
        if ((this->slideIndex >1)) previousSlide = this->slideList->at(this->slideIndex-2) ;
        this->slideIndex--;
        this->timer->stop();
        if (this->isSlideShowActive)
        {
            this->manager->getItsLoader()->setPreviousSlide(previousSlide);
            this->manager->getItsLoader()->setCurrentAction(ImageLoader::GetPreviousSlide);
            this->manager->getItsLoader()->setGoToSleepFalse();
            this->manager->getItsLoader()->newActionCondition.wakeAll();
            this->timer->start(this->manager->getItsProperty()->getSlideShowJumpTime()*1000);
        }
    }
}

/**
 * Displays message, that no files are selected
 */
void DisplayOperations::noSelectedFilesMessage()
{
    QMessageBox msgBox;
    msgBox.setStandardButtons(QMessageBox::Ok);
    msgBox.setText(tr("No files selected"));
    msgBox.setWindowTitle(tr("Error"));
    msgBox.setIcon(QMessageBox::Warning);
    msgBox.exec();
}

/**
 * Handels custom Event
 * @param event - event 
 */
void DisplayOperations::customEvent(QEvent * event)
{
    switch (event->type())
    {
    case ViewerEvent::NoFilesSelectedEvent:
        this->noSelectedFilesMessage();
        break;
    case ViewerEvent::ScrollToCurrentEvent:
        this->scrollToCurrentItem();
        break;
    default:
        break;
    }
}

/**
 * Scrolls widget that current widget will be visible
 */
void DisplayOperations::scrollToCurrentItem()
{
    QListWidgetItem *item = this->manager->getListWidget()->item(this->manager->getItsLoader()->getCurrentIndex()); 
    if (item!='\0')
    {
        this->manager->getListWidget()->scrollToItem(item,QAbstractItemView::PositionAtCenter);
    }
}

/**
* Handles Rotate action by degree
*/
void DisplayOperations::rotateImage(int degree)
{
    if (this->manager->isPresentationMode)
    {
        switch (degree)
        {
        case 90:
            this->manager->itsLoader->setCurrentAction(ImageLoader::Turn90);
            break;
        case 180:
            this->manager->itsLoader->setCurrentAction(ImageLoader::Turn180);
            break;
        case 270:
            this->manager->itsLoader->setCurrentAction(ImageLoader::Turn270);
            break;
        default:
            break;

        };
        this->manager->itsLoader->setGoToSleepFalse();
        this->manager->itsLoader->newActionCondition.wakeAll();
    }
    else
    {
        QList<QFileInfo*> *fileList = new QList<QFileInfo*>();
        QList<QListWidgetItem *> items = this->manager->getListWidget()->selectedItems();
        QListIterator<QListWidgetItem *> iterator(items);
        while (iterator.hasNext())
        {
            PictureListWidgetItem *item = dynamic_cast<PictureListWidgetItem*>(iterator.next());
            fileList->push_front(new QFileInfo(item->getFile()));
        }
        QList<ImageLoader::Action> actionList;

        switch (degree)
        {
        case 90:
            actionList.push_front(ImageLoader::Turn90);
            break;
        case 180:
            actionList.push_front(ImageLoader::Turn180);
            break;
        case 270:
            actionList.push_front(ImageLoader::Turn270);
            break;
        default:
            break;
        };
        new FileOperationsHandler(this->manager, FileOperationsHandler::SaveTransformedImage, fileList, actionList, false);
    }
}

/**
 * Context menu handler
 * @param event 
 */
void DisplayOperations::handleContextMenu(QContextMenuEvent * event)
{
    if (!this->manager->getIsPresentationMode() && this->manager->listWidget->underMouse())
    {

        QMenu contextMenu( this->manager->listWidget );
        contextMenu.addAction ( this->manager->renameAct );
        contextMenu.addAction ( this->manager->removeFilesAct);
        contextMenu.addAction ( this->manager->copyFilesAct );
        contextMenu.addAction (this->manager->moveFilesAct);
        contextMenu.addAction (this->manager->makeDirectoryAct);
        contextMenu.addSeparator();
	contextMenu.addAction( this->manager->slideShowAct);
        contextMenu.addAction ( this->manager->commentEditAct );
	contextMenu.addAction(this->manager->keywordsAct);
        contextMenu.addAction ( this->manager->commentRemoveAct );
        contextMenu.addSeparator();

        QMenu *rotateContextMenu = contextMenu.addMenu(tr("Rotate"));
        rotateContextMenu->addAction(this->manager->rotate90Act);
        rotateContextMenu->addAction(this->manager->rotate180Act);
        rotateContextMenu->addAction(this->manager->rotate270Act);
        contextMenu.exec( event->globalPos() );

    }
    else  if (this->manager->treeWidget->underMouse())
    {

        QAction *renameTreeAct = new QAction ( tr ( "&Rename" ), this );
        renameTreeAct->setShortcut ( tr ( "Ctrl+R" ) );
        renameTreeAct->setStatusTip ( tr ( "Change file name" ) );
        connect ( renameTreeAct, SIGNAL ( triggered() ), this->manager->filesOperations, SLOT ( renameTreeSlot() ) );

        QAction *removeFilesTreeAct = new QAction (tr ( "&Delete" ), this );
        removeFilesTreeAct->setStatusTip ( tr ( "Delete selected files" ) );
        connect ( removeFilesTreeAct, SIGNAL ( triggered() ), this->manager->filesOperations, SLOT ( deleteTreeSlot() ) );

        QAction *copyFilesTreeAct = new QAction (QIcon(":/copyFiles"),tr ( "&Copy" ), this );
        copyFilesTreeAct->setStatusTip ( tr ( "Copy directory`" ) );
        connect ( copyFilesTreeAct, SIGNAL ( triggered() ), this->manager->filesOperations, SLOT ( copyTreeSlot() ) );

        QAction *moveFilesTreeAct = new QAction (QIcon(":/moveFiles"), tr ( "&Move" ), this );
        moveFilesTreeAct->setStatusTip ( tr ( "Move directory" ) );
        connect ( moveFilesTreeAct, SIGNAL ( triggered() ), this->manager->filesOperations, SLOT ( moveTreeSlot() ) );

        QAction *slideShowTreeAct = new QAction (QIcon(":/slideshow"),tr ( "&Slide Show" ), this );
        slideShowTreeAct->setStatusTip ( tr ( "Activate Slide Show" ) );
        connect ( slideShowTreeAct, SIGNAL ( triggered() ), this, SLOT ( slideShowTreeSlot() ) );

        QMenu contextMenu(this->manager->listWidget) ;
        contextMenu.addAction (renameTreeAct );
        contextMenu.addAction(removeFilesTreeAct);
        contextMenu.addAction(copyFilesTreeAct);
        contextMenu.addAction(moveFilesTreeAct);
        contextMenu.addAction(this->manager->makeDirectoryAct);
        contextMenu.addSeparator();
        contextMenu.addAction(slideShowTreeAct);

        contextMenu.addSeparator();
        contextMenu.exec(event->globalPos());
    }
}

/**
 * Handles slide show procedure triggered by tree widget
 */
void DisplayOperations::slideShowTreeSlot()
{
    this->slideShowSlot(FilesOperations::TreeWidget);
}


/**
 * Clears Slide show list
 */
void DisplayOperations::clearSlideList()
{
	this->slideList->clear();
}

/**
 * Handles Search operation
 */
void DisplayOperations::searchSlot()
{
	SearchDialog *dialog = new SearchDialog(this->manager);
	if(dialog->exec()){
		SearchResultDialog *resultDialog = new SearchResultDialog(dialog->getSearchParameter()->getDir()->path(), this->manager);
                Finder *finder = new Finder(dialog->getSearchParameter(), (QObject*)resultDialog);
                resultDialog->exec();
                delete finder;
                delete resultDialog;
	}
        delete dialog;
}


/**
 * Opens Keywords dialog
 */
void DisplayOperations::keywordsSlot()
{
    if (this->manager->listWidget->selectedItems().count()>0)
    {
        KeywordsDialog dialog(this->manager);
        dialog.exec();
    }
}

/**
* Handles Rotate 90 degree action
*/
void DisplayOperations::rotateImage90()
{
    this->rotateImage(90);
}

/**
* Handles Rotate 180 degree action
*/
void DisplayOperations::rotateImage180()
{
    this->rotateImage(180);
}

/**
* Handles Rotate 270 degree action
*/
void DisplayOperations::rotateImage270()
{
    this->rotateImage(270);
}

/**
 * Display Next image in presentationWidget
 */
void DisplayOperations::displayNextImage()
{
    this->displayNextImage(false);
}

/**
 * Display Next image in presentationWidget
 */
void DisplayOperations::displayNextImage(bool reloadLoader)
{

    if (this->getIsSlideShowActive())
    {
        this->slideShowTimerTimeout();
    }
    else
    {
        ImageLoader *loader = this->manager->itsLoader;
        QListWidget *listWidget = this->manager->getListWidget();
        PictureListWidgetItem *item;
        int i = loader->getCurrentIndex();
        if (++i<listWidget->count())
        {
            loader->setCurrentAction(ImageLoader::GetNext);
            if (reloadLoader) loader->setCurrentAction(ImageLoader::GetNextAndReload);
            loader->setGoToSleepFalse();
            loader->newActionCondition.wakeAll();
            item = dynamic_cast<PictureListWidgetItem*> ( listWidget->item(i));
            listWidget->clearSelection();
            item->setSelected(true);
        }
    }
}

/**
 * Display Previous image in presentationWidget
 */
void DisplayOperations::displayPreviousImage()
{
    if (this->getIsSlideShowActive())
    {
        this->getPreviousSlide();
    }
    else
    {
        ImageLoader *loader = this->manager->itsLoader;
        QListWidget *listWidget = this->manager->getListWidget();
        PictureListWidgetItem *item;
        int i = loader->getCurrentIndex();
        if (--i>=0)
        {
            item = dynamic_cast<PictureListWidgetItem*> ( listWidget->item(i));
            if (!item->getFile().isDir())
            {
                loader->setCurrentAction(ImageLoader::GetPrevious);
                loader->setGoToSleepFalse();
                loader->newActionCondition.wakeAll();
                listWidget->clearSelection();
                item->setSelected(true);
            }
        }
    }
}

/**
 * Display correct image after deleting/moveing files
 */
void DisplayOperations::displayCorrectImage()
{

    QListWidget *listWidget = this->manager->getListWidget();
 
    int i =this->manager->itsLoader->getCurrentIndex();
    PictureListWidgetItem *item = dynamic_cast<PictureListWidgetItem*> (listWidget->item(i));
    delete item;
    listWidget->update();
    if (i>=listWidget->count())
    {
        this->displayPreviousImage();
    }
    else if (++i<listWidget->count())
    {
        this->displayNextImage(true);
    }
}
/**
 * Manages item selection changes (enables/disables keywords and comment edit dialog)
 */

void DisplayOperations::itemSelectionChanged()
{
    QList<QListWidgetItem *> items = this->manager->listWidget->selectedItems();
    if(items.count()>0){
        for(QList<QListWidgetItem *>::iterator it=items.begin(); it != items.end(); it++){
            PictureListWidgetItem *item = dynamic_cast<PictureListWidgetItem*>(*it);
            if(!item->getFile().isDir()){
                this->manager->keywordsAct->setEnabled(true);
                this->manager->commentEditAct->setEnabled(true);
                return;
            }
        }
    }
    this->manager->keywordsAct->setEnabled(false);
    this->manager->commentEditAct->setEnabled(false);
}

/**
 * handles file operation error
 * @param errorEvent
 */
void DisplayOperations::handleFileOperationError(FileOperationErrorEvent *errorEvent)
{
FileOperationsHandler *handler = errorEvent->getHandler();
int ret = this->displayOperationErrorDialog(errorEvent);
    switch (ret) {
    case QMessageBox::Cancel:
       	handler->setIsCanceled(true);
      	handler->waitError.wakeAll();
       break;
    case QMessageBox::No:
       handler->setForAll(false);
       handler->setYesAnswer(false);
       handler->waitError.wakeAll();
       break;
    case QMessageBox::Yes:
       handler->setForAll(false);
       handler->setYesAnswer(true);
       handler->waitError.wakeAll();
       break;
    case QMessageBox::YesToAll:
       handler->setForAll(true);
       handler->setYesAnswer(true);
       handler->waitError.wakeAll();
       break;
    case QMessageBox::NoToAll:
       handler->setForAll(true);
       handler->setYesAnswer(false);
       handler->waitError.wakeAll();
       break;
    default:
       // should never be reached
        break;
     }
}
/**
  *Construct and display file operation error Dialog
  *@returns int
  */
int DisplayOperations::displayOperationErrorDialog(FileOperationErrorEvent *event){
    QString file = event->getFileName();
    bool manyFiles = event->getManyFiles();

    QMessageBox messageBox;
    switch(event->getOperationType()){
        case FileOperationsHandler::Delete:
            messageBox.setText(tr("Cannot delete file: ") + file +tr("\nRetry?"));
            if(manyFiles){
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll |  QMessageBox::Cancel);
            } else{
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No |  QMessageBox::Cancel);
            }
        break;
        case FileOperationsHandler::RemoveComments:
            messageBox.setText(tr("Cannot delete comment file: ") + file +tr("\nRetry?"));
            if(manyFiles){
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll |  QMessageBox::Cancel);
            } else {
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
            }
        break;
        case FileOperationsHandler::Copy:
            messageBox.setText(tr("Cannot copy file ") + file +tr("\nRetry?"));
            if(manyFiles){
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll |  QMessageBox::Cancel);
            } else {
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
            }
        break;
        case FileOperationsHandler::MakeDir:
            messageBox.setText(tr("Cannot make directory ") + file +tr("\nRetry?"));
            messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No);
        break;
        case FileOperationsHandler::Rename:
            messageBox.setText(tr("Cannot rename file: ") + file +tr("\nRetry?"));
            if(manyFiles){
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll |  QMessageBox::Cancel);
            } else {
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No);
            }
        break;
        case FileOperationsHandler::SaveTransformedImage:
            messageBox.setText(tr("Cannot save file: ") + file +tr("\nRetry?"));
            if(manyFiles){
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll |  QMessageBox::Cancel);
            } else {
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No);
            }
        break;
        case FileOperationsHandler::Move:
            messageBox.setText(tr("Cannot move file: ") + file +tr("\nRetry?"));
            if(manyFiles){
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll |  QMessageBox::Cancel);
            } else {
                messageBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No);
            }
        break;
    }
    // choose cause of the error
    switch(event->getCause()){
        case FileOperationsHandler::FileDoesNotExist:
                messageBox.setInformativeText(tr("File does not exist"));
                break;
        case FileOperationsHandler::PermissionDenined:
                if(event->getOperationType()==FileOperationsHandler::Move){
                    messageBox.setInformativeText(tr("Permission denined, cannot copy file"));
                } else {
                    messageBox.setInformativeText(tr("Permision denined"));
                }
                break;
         case FileOperationsHandler::FileExist:
            if(event->getOperationType()==FileOperationsHandler::MakeDir){
                messageBox.setInformativeText(tr("Directory alerady Exist"));
            } else {
                 messageBox.setInformativeText(tr("File alerady Exist"));
            }
            break;
          case FileOperationsHandler::CannotDeleteFile:
                messageBox.setInformativeText(tr("Permission denined, cannot delete file"));
                break;
          case FileOperationsHandler::CannotReadFile:
                messageBox.setInformativeText(tr("Permission denined, cannot read file"));
                break;
         default:
                messageBox.setInformativeText("");
    }
    return messageBox.exec();
}

/*
 * Runs image properties dialog
 */
void DisplayOperations::imagePropertiesSlot(){
    PictureListWidgetItem *item = dynamic_cast<PictureListWidgetItem*>(this->manager->listWidget->currentItem());
    QPixmap *iconPixmap = new QPixmap(item->icon().pixmap(200, 200));
    QFileInfo *fileInfo = new QFileInfo(item->getFile());
    ImageProperties *dialog;
    if(this->manager->getIsPresentationMode()){
        dialog = new ImageProperties(*iconPixmap, *fileInfo, (QWidget*)this->manager->presentationWidget);
    } else {
        dialog = new ImageProperties(*iconPixmap, *fileInfo, (QWidget*)this->manager->browserWidget);
    }
    dialog->exec();
    delete dialog;
    delete iconPixmap;
    delete fileInfo;
}
